//
//  YZCoverView.m
//  患者信息界面（代码）
//
//  Created by Yip-Jun on 16/5/10.
//  Copyright © 2016年 YIPWJ. All rights reserved.
//

#import "YZSickMessageCoverView.h"
#import "Masonry.h"
#import "YZReservationView.h"

@interface YZSickMessageCoverView ()

@property (nonatomic, strong) YZReservationView *reservationView;

@property (nonatomic, strong) MASConstraint *oldLeadingConstraint;

@end

@implementation YZSickMessageCoverView

+ (instancetype)sickMessageCoverView:(YZDoctorModel *)doctorModel {
    
    YZSickMessageCoverView *coverView = [[YZSickMessageCoverView alloc] init];
    coverView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3];
    
    coverView.doctorModel = doctorModel;
    [coverView prepareUI];
    [coverView setSubviewsFrame];
    
    [UIView animateWithDuration:0.25 animations:^{
        [coverView updataSubviewsFrame];
    }];
    
    return coverView;
}

- (void)prepareUI {
    [self addSubview:self.reservationView];
}

- (void)updataSubviewsFrame {
    
    CGFloat superWidth = [UIScreen mainScreen].bounds.size.width;
    CGFloat superHeight = [UIScreen mainScreen].bounds.size.height;
    CGFloat width =  superWidth * 0.8;
    CGFloat height = superHeight * 0.6;
    CGFloat leading = (superWidth - width) * 0.5;
    CGFloat top = (superHeight - height) * 0.6;
    
    self.reservationView.frame = CGRectMake(leading, top, width, height);
}

- (void)setSubviewsFrame {
    
    self.reservationView.frame = CGRectMake(0, 0, 0, 0);
}


#pragma mark - 懒加载
- (YZReservationView *)reservationView {
    if (!_reservationView) {
        _reservationView = [YZReservationView reservationView:self.doctorModel];
        __weak __typeof(self)weakSelf = self;
        _reservationView.cannelButtonDidClickBlock = ^ {
            [UIView animateWithDuration:0.25 animations:^{
                CGFloat centerX = weakSelf.center.x;
                CGFloat centerY = weakSelf.center.y;
                weakSelf.reservationView.frame = CGRectMake(centerX, centerY, 0, 0);
            } completion:^(BOOL finished) {
                weakSelf.reservationViewCannelButtonDidClickBlock();
            }];
        };
    }
    return _reservationView;
}

@end
